export function setObjToUrlParams(
  baseUrl: string,
  obj: { [key: string]: any }
): string {
  let parameters = ''
  let url = ''
  for (const key in obj) {
    parameters += key + '=' + encodeURIComponent(obj[key]) + '&'
  }
  parameters = parameters.replace(/&$/, '')
  if (/\?$/.test(baseUrl)) {
    url = baseUrl + parameters
  } else {
    url = baseUrl.replace(/\/?$/, '?') + parameters
  }
  return url
}

// @description: 将参数放到url中（用于GET请求）
export function urlParams(url: string, params: Record<string, any>) {
  if (params) {
    const paramsArray: string[] = []
    //拼接参数
    Object.keys(params).forEach((key) => paramsArray.push(key + '=' + params[key]))
    if (url.search(/\?/) === -1) {
      url += '?' + paramsArray.join('&')
    } else {
      url += '&' + paramsArray.join('&')
    }
  }
  return url
}